package com.abc.controller;

import com.abc.entity.Product;
import com.abc.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

// 直接访问templates下的静态页面是无法获取static中的样式的
// 用该控制器进行去访问, 该控制器没有其他作用, 只是为了访问界面而已
@Controller
public class IndexController {
    @Autowired
    private ProductService productService;

    @GetMapping("/index")
    public String toIndex() {
        return "ims/login";
    }

    @GetMapping("/toRegister")
    public String toRegister() {
        return "ims/regist";
    }

    @GetMapping("/toSave")
    public String toSave() {
        return "ims/admin/addProduct";
    }

    @GetMapping("/visitorLogin")
    public String visitorLogin(Model model) {
        System.out.println("游客访问！");
        List<Product> products = productService.findAll();
        model.addAttribute("products", products);
        return "/ims/visitor/productlist";
    }
}
